package cn.tedu.ivos.geofence.service.impl;

import cn.tedu.ivos.geofence.mapper.GeofenceMapper;
import cn.tedu.ivos.geofence.pojo.dto.GeofenceParam;
import cn.tedu.ivos.geofence.pojo.dto.GeofenceQuery;
import cn.tedu.ivos.geofence.pojo.entity.Geofence;
import cn.tedu.ivos.geofence.pojo.vo.GeofenceVO;
import cn.tedu.ivos.geofence.service.GeofenceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
@Slf4j
@Service
public class GeofenceServiceimpl implements GeofenceService {
    @Autowired
    GeofenceMapper geofenceMapper;
    @Override
    public List<GeofenceVO> selectGeofence(GeofenceQuery geofenceQuery) {
        log.debug("开始处理【查询电子围栏】的业务，参数：{}", geofenceQuery);
        List<GeofenceVO>list= geofenceMapper.selectGeofence(geofenceQuery);
        return list;
    }

    @Override
    public void saveGeofence(GeofenceParam geofenceParam) {
        log.debug("开始处理【保存电子围栏】的业务，参数：{}", geofenceParam);
        Geofence geofence=new Geofence();
        BeanUtils.copyProperties(geofenceParam,geofence);
        if (geofence.getId()!=null){
            geofence.setUpdateTime(new Date());
            geofenceMapper.update(geofence);
        }else {
            geofence.setStatus("1");//每个围栏新增都是启用状态
            geofence.setCreateTime(new Date());
            geofenceMapper.insert(geofence);
        }


    }
}
